package com.qiantu.api.db.converter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qiantu.api.entity.DeviceCustomKeyBean;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.List;

/**
 * Description:
 * Author: cjc
 * Date: 2020/8/12 22:10
 */
public class DeviceCustomKeyPropertyConverter implements PropertyConverter<List<DeviceCustomKeyBean>, String> {
    @Override
    public List<DeviceCustomKeyBean> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null) {
            return null;
        }
        return new Gson().fromJson(databaseValue, new TypeToken<List<DeviceCustomKeyBean>>() {}.getType());
    }

    @Override
    public String convertToDatabaseValue(List<DeviceCustomKeyBean> entityProperty) {
        if (entityProperty == null) {
            return null;
        }
        return new Gson().toJson(entityProperty);
    }
}